﻿@*
    车间作业管理页面
     create date:
     last edit:
    2019.12.16 ben
     //显示剩余工时，remainWorkTime=FtotalWorkTime - ffinishtime；查询返回的totalworktime也已减除已完成；
    //添加只看本周以前任务单功能！按{计划开工日期、计划完工日期、审核日期}

*@

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>车间作业管理</title>
    <link href="~/Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js?v=0.1"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />


    <!--  <script src="~/Scripts/jquery-easyui/Extension/jquery-easyui-datagridview/datagrid-detailview.js"></script><script src="~/Content/js/jquery.jqprint-0.3.js"></script> <script src="~/Content/js/printDatagrid.js"></script>-->

    <script type="text/javascript">
        var YiLingliao = false;//查询条件：以领料
        var beforeThisWeek = true; //查询条件：仅本周以前
        var refDate = "planStartDate";
        //var totalWorkTime = 0;
        //表格列定义
        var myColums = [[
                {
                    title: '编号', field: 'ficmono', styler: function (value, row, index) {
                        if (row.isRush) {//紧急订单设为红色
                            return 'background-color:#FF3333;color:#fff;';
                        }
                        //else if (row.isRush) {//未开工
                        //    // return 'background-color:#FFFF66;color:blue;font-weight:bold;';
                        //}
                    }
                },
             { title: '产品名称', field: 'FName', },
             { title: '是否加急', field: 'isRush', hidden: true, },
             { title: '规格型号', field: 'FModel' },
             { width: 50, title: '数量', field: 'FQTYPLAN' },
             { width: 90, title: '计划开工日期', field: 'FPLANSTARTDATE', sortable: true, formatter: getDate },
             { width: 90, title: '计划完工日期', field: 'FPLANENDDATE', sortable: true, formatter: getDate },
             { width: 90, title: '实际开工日期', field: 'FStartWorkDate', sortable: true, formatter: getDate },
             { width: 90, title: '实际完工日期', field: 'FEndWorkDate', sortable: true, formatter: getDate },
             { width: 90, title: '审核日期', field: 'fcheckdate', sortable: false, formatter: getDate },
             { field: 'fopernote', width: 70, title: '工序名称', align: 'right' },
             {
                width: 60, title: '单据状态', field: 'FStatus', formatter: function (value, row, index) {
                    var x;
                    switch (value) {
                        case 0:
                            x = "计划";
                            break;
                        case 1:
                            x = "审核";
                            break;
                        case 2:
                            x = "审核";
                            break;
                        case 3:
                            x = "已完成";
                            break;
                        default:
                            x = value;
                    }
                    return x;
                }
            },
            { width: 80, title: '工作中心名称', hidden: true, field: 'FWorkCenterID', formatter: function (value, row, index) { if (value == 15293) { return '制造部' }; if (value == 16015) { return '委外' }; return value } },
            { width: 60, title: '运行时间', field: 'FtotalWorkTime', hidden: true, },
             { width: 60, title: '已完成时间', field: 'ffinishtime', hidden: true, },
             { width: 60, title: '剩余时间', field: 'remainWorkTime', formatter: function (value, row, index) { return row.FtotalWorkTime - row.ffinishtime } },
            {
                width: 60, title: '是否领料', field: 'ppbomstatus', hidden: false,
                formatter: function (value, row, index) {
                    return value == 1 ? '<img src="../../Content/themes/icon/chk_checked.gif" alt="已领料" title="已领料" />' : '<img src="../../Content/themes/icon/chk_unchecked.gif" alt="未领料" title="未领料" />';
                }
            },

        ]];



        $(function () {
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "ShopJobMgr", "KeyName": "ShopJobMgr" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {
                        //data.toolbar.push({ "text": "仅计划状态", "id": "btUnselectAll", "iconCls": "icon-link", "handler": "$('#ui_produce_dg').datagrid('clearSelections').datagrid('clearChecked');" })
                        //data.toolbar.push('-', { "text": "仅审核状态", "id": "btUnselectAll", "iconCls": "icon-link", "handler": "$('#ui_produce_dg').datagrid('clearSelections').datagrid('clearChecked');" })
                         //var toolbar = getToolBar(data);      //common.js
                        if (data.search) {     //判断是否有浏览权限
                            $("#ui_shopjob_dg").datagrid({
                                url: "/Produce/GetPageShopJob",
                                queryParams: {
                                    ficmono: $('#ficmono').val(),
                                    FName: $('#FName').val(),
                                    FStatus: $('#FStatus').val(),
                                    FModel: $('#FModel').val(),
                                    FWorkCenterID: $('#FWorkCenterID').val(),
                                    fopernote: $('#fopernote').val(),
                                    FPLANSTARTDATE: $('#FPLANSTARTDATE').datetimebox('getValue'),
                                    YiLingliao: YiLingliao,
                                    beforeThisWeek: beforeThisWeek, //查询条件：仅本周以前
                                    refDate: refDate //查询条件：仅本周以前参考日期取值
                                },
                                striped: true, rownumbers: true, pagination: true, pageSize: 10, singleSelect: false, border: true,
                                fitColumns: false,
                                idField: 'rownum',
                                sortName: 'FPLANENDDATE',
                                sortOrder: 'asc',
                                pageList: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
                                frozenColumns: [],
                                columns: myColums,
                                onSelect: function (rowIndex, rowData) {
                                    showmsg(rowIndex, rowData);
                                },
                                onUnselect: function (rowIndex, rowData) {
                                    showmsg(rowIndex, rowData);
                                },
                                //onClickRow:	function (rowIndex, rowData) {
                                //    showmsg(rowIndex, rowData);
                                //},
                                onDblClickRow: function (rowIndex, rowData) {
                                    $('#shopjobw').window('open');
                                    loadwork(rowIndex, rowData);
                                },
                                //toolbar: toolbar.length == 0 ? null : toolbar,
                                toolbar: [
                                     {
                                         text: '清除选择',
                                         iconCls: 'icon-chk_unchecked',
                                         handler: function () {
                                             $("#ui_shopjob_dg").datagrid('clearSelections').datagrid('clearChecked');
                                             showmsg_allworktime();//显示当前页面总工时
                                         }
                                     },
                                        {
                                            text: '仅计划订单',
                                            iconCls: 'icon-search',
                                            handler: function () {
                                                $('#FStatus').val("0");
                                                ui_shopjob_searchdata();                                               
                                            }
                                        }, '-', {
                                            text: '已审核订单',
                                            iconCls: 'icon-search',
                                            handler: function () {
                                                $('#FStatus').val("1");
                                                ui_shopjob_searchdata();
                                            }
                                        },  '-', {
                                            text: '全部未完成订单',
                                            iconCls: 'icon-search',
                                            handler: function () {
                                                $('#FStatus').val("selected");
                                                ui_shopjob_searchdata();
                                            }
                                        }, '-',
                                        { "text": "已领料" }, { "id": "sb_YiLingliao", }, '-',
                                        { "text": "仅本周以前订单" }, { "id": "sb_beforeThisWeek", },  { "id": "combo_date", },
                                    ],
                                onLoadSuccess: function (data) {
                                    showmsg_allworktime();//显示当前页面总工时

                                    //是否已领料开关初始化
                                    $('#sb_YiLingliao').switchbutton({
                                        checked: YiLingliao,
                                        onText: '是',
                                        offText: '否',
                                        onChange: function (checked) {
                                            YiLingliao = checked;
                                            ui_shopjob_searchdata();
                                        }
                                    });

                                    //是否仅显示本周前开关初始化                                  
                                    $('#sb_beforeThisWeek').switchbutton({
                                        checked: beforeThisWeek,
                                        onText: '是',
                                        offText: '否',
                                        onChange: function (checked) {
                                            beforeThisWeek = checked;
                                            ui_shopjob_searchdata();
                                        }
                                    });
                                    $('#combo_date').combobox({
                                        label: '基于',
                                        labelWidth:35,
                                        width: 150,
                                        value:refDate,
                                        data: [{
                                            label: '计划开工日期',
                                            value: 'planStartDate',
                                            //selected: true
                                        }, {
                                            label: '计划完工日期',
                                            value: 'planEndDate'
                                        }, {
                                            label: '审核日期',
                                            value: 'checkDate'
                                        }],
                                        valueField: 'value',
                                        textField: 'label',
                                        onChange: function (newValue, oldValue) {
                                            if (newValue !=refDate){
                                            refDate = newValue;//切换查询参考时间；
                                              ui_shopjob_searchdata();}
                                        }
                                    });

                                }
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })
            //回车搜索
            $("#ui_shopjob_search").find('input').on('keyup', function (event) {
                if (event.keyCode == '13') {
                    ui_shopjob_searchdata();
                }
            })
        });
        function showmsg_allworktime() {
            totalWorkTime = $("#ui_shopjob_dg").datagrid('getData').totalWorkTime;//更新总工时
            var text = stringFormat("当前查询结果合计总工时为{0}。", totalWorkTime.toFixed(2));
            $('#msg').html(text);
        }

        function showmsg(rowIndex, rowData) {
            var rows = $("#ui_shopjob_dg").datagrid("getSelections");
            if (rows.length > 0) {
                var totalworktime = 0;
                var finishedWorkTime = 0;
                for (var i = 0; i < rows.length; i++) {
                    totalworktime += rows[i].FtotalWorkTime;
                    finishedWorkTime += rows[i].ffinishtime; 
                } 
                var text = stringFormat("您选择了{0}行，合计运行时间为{1}。", rows.length, (totalworktime - finishedWorkTime).toFixed(2));
                $('#msg').html(text)
                return;
            } else {
                $('#msg').html("");
            }
        }



        function loadwork(rowIndex, rowData) {
            //动态加载标题和数据，显示项目对应的工序计划；
            $("#pworktable").datagrid({
                class: "easyui-datagrid"
            });
            $.ajax({
                url: "/Project/GetPageProcessInfo?FBillNo=" + rowData['ficmono'],// + "&FName=" + rowData['FName'],
                type: "post",
                dataType: "text",
                success: function (result) {
                    map = $.parseJSON(result);
                    if (map.rows) {
                        //   $("#pworktable").datagrid({
                        //     columns: [map.titleds]    //动态取标题
                        // });

                        //json数据中增加新列
                        for (var k in map.rows) {
                            map.rows[k]['FName'] = rowData['FName'];
                        }
                        $('#pworktable').datagrid('loadData', map.rows); //将返回的数据绑定到datagrid
                        //var col =  $('#pworktable').datagrid('getColumnOption', 'fitemid');
                        //col.value = rowData['FName']

                    } else {
                        $.messager.alert('Info', "没有找到记录！", 'info');
                    }

                }
            });
        }

        //主表绑定双击事件；
        $(function () {
            $('#ui_shopjob_dg').datagrid({
                onDblClickRow: function (rowIndex, rowData) {
                    $('#w').window('open');
                    loadwork(rowIndex, rowData);
                }
            });
        });


        //搜索任务单
        function ui_shopjob_searchdata(){
            $("#ui_shopjob_dg").datagrid('load', {
                ficmono: $('#ficmono').val(), 
                FName: $('#FName').val(),
                FStatus: $('#FStatus').val(),
                FModel: $('#FModel').val(),
                FWorkCenterID: $('#FWorkCenterID').val(),
                fopernote: $('#fopernote').val(),
                FPLANSTARTDATE: $('#FPLANSTARTDATE').datetimebox('getValue'),
                YiLingliao: YiLingliao,
                beforeThisWeek:beforeThisWeek, //查询条件：仅本周以前
                refDate: refDate //查询条件：仅本周以前参考日期取值
            });
            $("#ui_shopjob_dg").datagrid('clearSelections').datagrid('clearChecked');
        }
        //清除搜索条件
        function ui_shopjob_cleardata() {
            $('#ui_shopjob_search input').val('');
            $('#ui_shopjob_search select').val('select');
            $('#txtAddBeginDate').datetimebox('setValue', '');
            $('#txtAddEndDate').datetimebox('setValue', '');
        }

    </script>

</head>
<body class="easyui-layout">
    <div data-options="region:'north',split:true,minHeight:150" style="height:auto;">
        <div class="easyui-panel" title="工艺产能预警--根据当前用户角色过滤"
             style="width: auto;overflow:auto;height:auto;padding:1px;background:#fafafa;"
             data-options="closable:true,collapsible:false,minimizable:false,maximizable:false,href:'/CapacityEst/shopJobOperAlert'">
            <p>数据加载中...</p>
        </div>
    </div>

    <div data-options="region:'center'," style="padding:5px;background:#eee;">
        <div id="ui_shopjob_layout" class="easyui-layout" data-options="fit:true,border:false">
            <div data-options="region:'north',split:true,border:true,collapsed:true" title="条件搜索" style="height:110px;">
                <div id="ui_shopjob_search">
                    <table class="tableForm" style="width: 99%; height: 100%; background: #F5F5F5;">
                        <tr>
                            <th>
                                编号：
                            </th>
                            <td>
                                <input name="ficmono" id="ficmono" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                            </td>

                            <th>
                                物料名称：
                            </th>
                            <td>
                                <input name="FName" id="FName" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                            </td>
                            <th>
                                工序名称：
                            </th>
                            <td>
                                <input name="fopernote" id="fopernote" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                            </td>

                            <th>
                                订单状态：
                            </th>
                            <td>
                                <select name="FStatus" id="FStatus">
                                    <option value="" selected="selected">全部未完成</option>
                                    <option value="0">未开始</option>
                                    <option value="1">已开始未完成</option>
                                    <option value="2">全部</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                计划开工时间：
                            </th>
                            <td>
                                <input name="FPLANSTARTDATE" id="FPLANSTARTDATE" class="easyui-datetimebox"
                                       editable="false" style="width:150px;height:22px;" />
                            </td>
                            <th>
                                工作中心：
                            </th>
                            <td>
                                <select name="FWorkCenterID" id="FWorkCenterID">
                                    <option value="0" >全部</option>
                                    <option value="15293" selected="selected">制造部</option>
                                    <option value="16015">委外</option>
                                </select>
                            </td>
                            <th>
                                规格型号：
                            </th>
                            <td>
                                <input name="FModel" id="FModel" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                            </td>

                            <td colspan="4">
                                <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                                   onclick="ui_shopjob_searchdata();">搜索</a>
                                <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                                   onclick="ui_shopjob_cleardata();">清空条件</a>
                                @*<a href="javascript:void(0);" onclick="CreateFormPage('打印测试', $('#ui_produce_dg'));">打印</a>*@
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div data-options="region:'center',border:true,maxHeight:400">
                <table id="ui_shopjob_dg" data-options="fit:true,border:true"></table>
            </div>
        </div>
    </div>
    <div data-options="region:'south',split:false,border:false,collapsed:false,collapsible:false" style="height:22px;padding:1px">
        <div id="msg"> 您当前选择了0条工单. </div>
    </div>


</body>

@*<div id="shopjobw" class="easyui-window" title="工序计划表" closed="true" data-options="iconCls:'icon-save',minimizable:false,tools:'#tt'" style="width:990px;height:400px;padding:10px;">
    <table id="pworktable" data-options="rownumbers:true, singleSelect:true, autoRowHeight:false, pagination:false, resizeHandle:'right'">
        <thead>
            <tr>
                <th data-options="field:'ficmono',width:90">编号</th>
                <th data-options="field:'FName',width:80">产品名称</th>
                <th data-options="field:'FQTYPLAN',width:50">数量</th>
                <th data-options="field:'FPLANSTARTDATE',width:80,align:'center',formatter: function (value, row, index) { return value.substring(0, value.indexOf(' ')) }">计划开工日期</th>
                <th data-options="field:'FPLANENDDATE',width:80,align:'center',formatter: function (value, row, index) { return value.substring(0, value.indexOf(' ')) }">计划完工日期</th>
                <th data-options="field:'FStartWorkDate',width:80,align:'center', formatter: function (value, row, index) { return value.substring(0, value.indexOf(' ')) }">实际开工日期</th>
                <th data-options="field:'FEndWorkDate',width:80,align:'center',formatter: function (value, row, index) { return value.substring(0, value.indexOf(' ')) }">实际完工日期</th>
                <th data-options="field:'fcheckdate',width:70,align:'right',formatter: function (value, row, index) { return value.substring(0, value.indexOf(' ')) }">审核日期</th>
                <th data-options="field:'fopernote',width:70,align:'right'">工序名称</th>
                <th data-options="field:'fstatus',width:70,align:'right',formatter: function (value, row, index) { if(value==0){return '计划'};if(value==1){return '审核'};if(value==3){return '已完成'};return value}">单据状态</th>
                <th data-options="field:'FWorkCenterID',width:80,formatter:function (value, row, index) { if(value==15293){return '制造部'};if(value==16015){return '委外'};return value }">工作中心名称</th>
                <th data-options="field:'ffinishtime',width:80,align:'center'">运行时间</th>
            </tr>
        </thead>
    </table>
</div>*@

</html>
